import pandas as pd

s = pd.Series([2, 1, 3, 5, 4],
              index=['h3', 'h2', 'h1', 'h5', 'h4'])

# 按值排序
sort_value = s.sort_values()
print(sort_value)

# 按标签排序
sort_index = s.sort_index()
print(sort_index)

# 筛选
filtrate_s = s[s%2==0]
print(filtrate_s)
print("===========================")
# 拼接
s2 = pd.Series(['a', 'b', 'c', 'd', 'e'])
s_and_s2 = pd.concat([s, s2])   # 默认按行拼接 也就是axis=0
print(s_and_s2)
print("=================")
s_and_s2 = pd.concat([s, s2], axis=1)
print(s_and_s2)

s = pd.Series([1, 2, 3, 4, 5])
s2 = pd.Series(['a', 'b', 'c', 'd', 'e'])
s_and_s2 = pd.concat([s, s2], axis=1)
print(s_and_s2)

# ms1 = pd.Series([1, 2, 3, 4, 5], name="张三")
# ms2 = pd.Series(['a', 'b', 'c', 'd', 'e'], name="李四")
# s1_merge_s2 = pd.merge(ms1, ms2)
# print(s1_merge_s2)
# 将这块内容拿到DataFrame中讲解

print("========================================")
import pandas as pd

# 一周营业额数据
s = pd.Series([1, 2, 3, 4, 5, 6, 7])

# 1、滚动统计【固定窗口】
roll_s = s.rolling(window=3)
print(roll_s)
print("========================================")
print(roll_s.sum())

# 2、扩展窗口
expand_s = s.expanding()
print(expand_s)
print("========================================")
print(expand_s.sum())

# 3、累计统计
cumsum_s = s.cumsum()
print(cumsum_s)
print("========================================")
cummax_s = s.cummax()
print(cummax_s)


import matplotlib.pyplot as plt
import pandas as pd

# 一周营业额数据
s = pd.Series([1, 2, 3, 10, 5, 6, 7],
              index=['w1', 'w2', 'w3', 'w4', 'w5', 'w6', 'w7'])

# pandas与matplotlib是无缝集成的
s.plot(kind="line",         # 设置图标类型
       title="Line Plot",   # 设置标题
       grid=True,           # 显示网格线
       style="r--s",        # 设置线型颜色标记类型
       lw=2,                # 线宽
       figsize=(8,6)        # 图纸窗口figure的大小，单位是英寸
       )

plt.show()